<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Bmob 数据提交示例</title>
</head>

<body>
    <button onclick="submitStudent()">提交学生数据</button>
    <pre id="result"></pre>

    <script>
        // Bmob 配置（替换为你的真实密钥）
        const Bmob = {
            Application_ID: "bcc86d3a5076794cbada268bfc2a79fe", // 从 Bmob 后台获取
            REST_API_Key: "42d9429f857a423137ba00bb94422d8d"     // 从 Bmob 后台获取
        };

        async function submitStudent() {
            const url = "https://api.bmobapp.com/1/classes/Student"; // 确保表名已创建
            const data = {
                name: "张三呀",
                score: 90,
                class: "A班"
            };

            try {
                const response = await fetch(url, {
                    method: "POST",
                    headers: {
                        "Content-Type": "application/json",
                        "X-Bmob-Application-Id": Bmob.Application_ID,
                        "X-Bmob-REST-API-Key": Bmob.REST_API_Key
                    },
                    body: JSON.stringify(data)
                });

                const result = await response.json();
                document.getElementById("result").innerHTML =
                    `提交成功！\nID: ${result.objectId}\n创建时间: ${result.createdAt}`;
            } catch (error) {
                document.getElementById("result").innerHTML =
                    `提交失败！\n错误详情: ${error.message}\n请检查：\n1. 密钥是否正确\n2. 表名是否已创建\n3. 网络是否正常`;
            }
        }
    </script>
</body>

</html>